﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PS3Packager
{
    public partial class UploadToPS3Form : Form
    {
        public UploadToPS3Form()
        {
            InitializeComponent();
        }

        private void buttonBrowseLocalFolder_Click(object sender, EventArgs e)
        {
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string UriStr
        {
            get { return ftpEditor.UriStr; }
            set { ftpEditor.UriStr = value; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Uri FtpUri
        {
            get { return ftpEditor.FtpUri; }
            set { ftpEditor.FtpUri = value; }
        }

        public string LocalPackageFile
        {
            get { return textEditLocalPkgFile.Text; }
            set { textEditLocalPkgFile.Text = value; }
        }

        private void buttonUpload_Click(object sender, EventArgs e)
        {
            // errorProvider.Clear();
            ValidateChildren();
            if (!errorProvider.HasErrors())
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        private void textEditLocalPkgFile_BrowseButtonClicked(UserControls.TextEditBrowse sender)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.CheckFileExists = true;
            ofd.Filter = "PS3 package File|*.pkg|All Files|*.*";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textEditLocalPkgFile.Text = ofd.FileName;
            }
        }

        private void textEditLocalPkgFile_Validating(object sender, CancelEventArgs e)
        {
            if (!File.Exists(textEditLocalPkgFile.Text))
            {
                errorProvider.SetIconAlignment(textEditLocalPkgFile, ErrorIconAlignment.MiddleLeft);
                errorProvider.SetError(textEditLocalPkgFile, "File not found");
            }
        }

        private void errorProvider_ErrorStateChanged(CustomControls.ExtendedErrorProvider sender, bool haserrors)
        {
            buttonUpload.Enabled = !haserrors;
        }

        private void UploadToPS3Form_Shown(object sender, EventArgs e)
        {
            ValidateChildren();
        }
    }
}
